package com.bing.services.impl;

import com.bing.entity.TUrl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Created by kaibb on 2016/6/4.
 */
public class TUService {
    private static Map<String, Integer> toBeScanning = new HashMap<>();

    public static Set<String> getToBeScanned() {
        Set<String> res = new HashSet<>();
        for (String tUrl : toBeScanning.keySet()) {
            if (toBeScanning.get(tUrl) == 0) {
                res.add(tUrl);
            }
        }
        return res;
    }

    public static void addToScan(Set<String> urls) {
        for (String url : urls) {
            if (toBeScanning.containsKey(url)) {
                continue;
            }
            if (url.contains("pan.baidu.com")) {
                toBeScanning.put(url, 1);
            } else if (url.endsWith(".rar") || url.endsWith(".jpg") || url.endsWith(".js") || url.endsWith("png") || url.endsWith("css")) {
                toBeScanning.put(url, 1);
            } else {
                toBeScanning.put(url, 0);
            }

        }

    }

    public static void setScanned(Set<String> urls) {
        for (String url : urls) {
            toBeScanning.put(url, 1);
        }
    }

    public static void clear(){
        toBeScanning.clear();
    }
    public static Set<String> getAll() {
        return toBeScanning.keySet();
    }
}
